package com.example.j20240419springaop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
public class AspectDemo1 {
    //定义切点
    @Pointcut("execution(* com.example.j20240419springaop.controller.*.*(..))")
    public void pt() {};
    @Before("pt()")
    public void doBefore() {
        log.info("doBefore");
    }

    @After("pt()")
    public void doAfter() {
        log.info("doAfter");
    }

    @AfterReturning("pt()")
    public void doAfterReturning() {
        log.info("doAfterReturning");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("doAfterThrowing");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("before doAround");

        Object result = joinPoint.proceed();

        log.info("after doAround");

        return result;
    }
}
